<?php
/**
 * 网站配置信息控制器
 */
class WebsetController extends IsLoginController{
	public function index(){
		$model= K('config');
		$webSetInfo = M('config')->all();
//		var_dump($webSetInfo);die;
		$this->assign('webSetInfo',$webSetInfo);
		//调用读取模板目录
//		$dirArr = Dir::tree('Template');
//		var_dump($dirArr);
		$templateDir = glob('Template/*');
		$dir = array();
		foreach($templateDir as $k =>$v){
			$v = basename($v);
			$dir[]  = $v;
		}
		$this->assign('dir',$dir);
		if(IS_POST){
		//写入配置项到数据库
			foreach(Q('post.') as $k => $v){
				$model->where("name='{$k}'")->update(array('value'=>$v));
			}
			//写入配置文件
			$data = $model->all();
			$temp = array();
			//重组格式
			foreach($data as $v){
				$temp[$v['name']] =$v['value'];
			}
			$temp = var_export($temp,true);
			$str = <<<str
<?php
if (!defined("HDPHP_PATH"))exit('No direct script access allowed');
return {$temp};
?>
str;
			file_put_contents(APP_CONFIG_PATH.'/websetConfig.php', $str);
			$this->success('修改成功');
			
		}
		$this->display();
	}
}
